home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / MOUSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-29  |  12.0 KB  |  397 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    New mouse driver and creation                                    *
  4.  *                                                                    *
  5.  *    Copyright (C) 1993 - 1994, Bitgate Software and Clever Bits.    *
  6.  *    All rights reserved.                                            *
  7.  *                                                                    *
  8.  *    Handles the changing of mouse forms, the animation (crude) of    *
  9.  *    mouse forms, and the management of current and previous mouse    *
  10.  *    forms.  These routines are just plain smart.                    *
  11.  *                                                                    *
  12.  ********************************************************************
  13.  *                                                                    *
  14.  *    Update log:                                                        *
  15.  *                                                                    *
  16.  *    [21.11.93 - 13.3.94] Ken Hollis                                    *
  17.  *        WGrafMouse        - created                                    *
  18.  *                        - added new icons for mice                    *
  19.  *                        - added option to return current mouse form    *
  20.  *                        - added option to store mouse form after    *
  21.  *                            found from special mouse settings        *
  22.  *                        - added fix for no more compilation warnings*
  23.  *                        - made mouse changes smarter (no change if    *
  24.  *                            mouse is already the assigned form)        *
  25.  *                                                                    *
  26.  *    Need to add animated mice via assembly routines, multi-coloured    *
  27.  *    mice.  Also need to add M_SAVE, M_RESTORE, M_PREVIOUS for        *
  28.  *    compatibility.                                                    *
  29.  *                                                                    *
  30.  ********************************************************************/
  31.  
  32. #include <aes.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. #include "winlib.h"
  37.  
  38. #ifndef __MOUSE__
  39. #define __MOUSE__
  40. #endif
  41.  
  42. MICE mouseform;    /* forms */
  43. int cur_mouse = 1, cur_mouse_form = BUSYBEE;
  44.  
  45. int init_mouse[37] =
  46. { 8, 8, 1, 0, 1, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  47.   0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x7FFE, 0xFFFF,
  48.   0xFFFF, 0xFFFF, 0x0000, 0x7FFE, 0x4002, 0x43C2, 0x47E2, 0x47E2,
  49.   0x43C2, 0x4002, 0x43C2, 0x4002, 0x7FFE, 0x1008, 0x2D74, 0x4002,
  50.   0x7FFE, 0x0000 };
  51.  
  52. int loadresource_mouse[37] =
  53. { 8, 8, 1, 0, 1, 0x3FFF, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  54.   0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  55.   0xFFFF, 0xFFFF, 0x0000, 0x1FFE, 0x28F2, 0x48F2, 0x48F2, 0x48F2,
  56.   0x4FF2, 0x4002, 0x5DDA, 0x5512, 0x59D2, 0x5452, 0x55DA, 0x4002,
  57.   0x7FFE, 0x0000 };
  58.  
  59. int lrmove_mouse[37] =
  60. { 8, 8, 1, 0, 1, 0x0000, 0x0000, 0x0000, 0x1E78, 0x3E7C, 0x7E7E,
  61.   0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x7E7E, 0x3E7C, 0x1E78, 0x0000,
  62.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C30, 0x1C38,
  63.   0x3C3C, 0x7FFE, 0x7FFE, 0x3C3C, 0x1C38, 0x0C30, 0x0000, 0x0000,
  64.   0x0000, 0x0000 };
  65.  
  66. int lrsize_mouse[37] =
  67. { 8, 8, 1, 0, 1, 0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x07E0,
  68.   0xFFE0, 0xFFF7, 0xFFFF, 0xFFFF, 0xFFFF, 0x01FF, 0x00FF, 0x01FF,
  69.   0x01FF, 0x01FF, 0x0000, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x03C0,
  70.   0x03C0, 0x7FC0, 0x7FE2, 0x7FF6, 0x00FE, 0x007E, 0x003E, 0x007E,
  71.   0x00FE, 0x0000 };
  72.  
  73. int llsize_mouse[37] =
  74. { 8, 8, 1, 0, 1, 0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x07E0,
  75.   0x07FF, 0xEFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFF80, 0xFF00, 0xFF80,
  76.   0xFF80, 0xFF80, 0x0000, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x03C0,
  77.   0x03C0, 0x03FE, 0x47FE, 0x6FFE, 0x7F00, 0x7E00, 0x7C00, 0x7E00,
  78.   0x7F00, 0x0000};
  79.  
  80. int ulsize_mouse[37] =
  81. { 8, 8, 1, 0, 1, 0xFF80, 0xFF80, 0xFF80, 0xFF00, 0xFF80, 0xFFFF,
  82.   0xFFFF, 0xFFFF, 0xEFFF, 0x07FF, 0x07E0, 0x07E0, 0x07E0, 0x07E0,
  83.   0x07E0, 0x07E0, 0x0000, 0x7F00, 0x7E00, 0x7C00, 0x7E00, 0x7F00,
  84.   0x6FFE, 0x47FE, 0x03FE, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x03C0,
  85.   0x03C0, 0x0000 };
  86.  
  87. int ursize_mouse[37] =
  88. { 8, 8, 1, 0, 1, 0x01FF, 0x01FF, 0x01FF, 0x00FF, 0x01FF, 0xFFFF,
  89.   0xFFFF, 0xFFFF, 0xFFF7, 0xFFE0, 0x07E0, 0x07E0, 0x07E0, 0x07E0,
  90.   0x07E0, 0x07E0, 0x0000, 0x00FE, 0x007E, 0x003E, 0x007E, 0x00FE,
  91.   0x7FF6, 0x7FE2, 0x7FC0, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x03C0,
  92.   0x03C0, 0x0000 };
  93.  
  94. int udmove_mouse[37] =
  95. { 8, 8, 1, 0, 1, 0x0000, 0x03C0, 0x07E0, 0x0FF0, 0x1FF8, 0x1FF8,
  96.   0x1FF8, 0x03C0, 0x03C0, 0x1FF8, 0x1FF8, 0x1FF8, 0x0FF0, 0x07E0,
  97.   0x03C0, 0x0000, 0x0000, 0x0000, 0x0180, 0x03C0, 0x07E0, 0x0FF0,
  98.   0x0180, 0x0180, 0x0180, 0x0180, 0x0FF0, 0x07E0, 0x03C0, 0x0180,
  99.   0x0000, 0x0000 };
  100.  
  101. int clip_mouse[37] =
  102. { 0x0008,0x0008,0x0001,0x0000,0x0001, 0x03C0,0x0660,0x1DB8,0xF18F,
  103.     0x87E1,0xBFFD,0xBFFD,0xBFFD, 0xBFFD,0xBFFD,0xBFFD,0xBFFD,
  104.     0xBFFD,0xBFFD,0x8001,0xFFFF, 0x0000,0x0180,0x0240,0x0E70,
  105.     0x781E,0x5FFA,0x500A,0x570A, 0x514A,0x500A,0x536A,0x500A,
  106.     0x5FFA,0x4002,0x7FFE,0x0000 };
  107.  
  108. int dial_mouse[37] =
  109. { 0x0008,0x0008,0x0001,0x0000,0x0001, 0xFFFF,0x8001,0xBFFD,0xBFFD,
  110.     0xBFFD,0xBFFD,0xBFFD,0xBFFD, 0xBFFD,0xBFFD,0xBFFD,0xBFFD,
  111.     0xBFFD,0xBFFD,0x8001,0xFFFF, 0x0000,0x7FFE,0x4422,0x55AA,
  112.     0x4422,0x7FFE,0x4002,0x47C2, 0x4662,0x4662,0x4662,0x4662,
  113.     0x47C2,0x4002,0x7FFE,0x0000 };
  114.  
  115. int text_mouse[37] =
  116. { 0x0008,0x0008,0x0001,0x0000,0x0001, 0xFFFF,0x8001,0xBFFD,0xBFFD,
  117.     0xBFFD,0xBFFD,0xBFFD,0xBFFD, 0xBFFD,0xBFFD,0xBFFD,0xBFFD,
  118.     0xBFFD,0xBFFD,0x8001,0xFFFF, 0x0000,0x7FFE,0x4422,0x55AA,
  119.     0x4422,0x7FFE,0x4002,0x5EDA, 0x4CDA,0x4C72,0x4C72,0x4CDA,
  120.     0x4CDA,0x4002,0x7FFE,0x0000 };
  121.  
  122. int timer_mouse[37] =
  123. { 0x0008,0x0008,0x0001,0x0000,0x0001, 0xFFFF,0x8001,0xBFFD,0xBFFD,
  124.     0xBFFD,0xBFFD,0xBFFD,0xBFFD, 0xBFFD,0xBFFD,0xBFFD,0xBFFD,
  125.     0xBFFD,0xBFFD,0x8001,0xFFFF, 0x0000,0x7FFE,0x4422,0x55AA,
  126.     0x4422,0x7FFE,0x4002,0x47E2, 0x4182,0x4182,0x4182,0x4182,
  127.     0x4182,0x4002,0x7FFE,0x0000 };
  128.  
  129. int trash_mouse[37] =
  130. { 0x0008,0x0008,0x0001,0x0000,0x0001, 0x07E0,0x0420,0x3DBC,0x6186,
  131.     0xCFFB,0xBFFD,0xBFFD,0xBFFD, 0xBFFD,0xBFFD,0xBFFD,0xBFFD,
  132.     0x9FF9,0xDFFB,0x4002,0x7FFE, 0x0000,0x03C0,0x0240,0x1E78,
  133.     0x324C,0x4002,0x524A,0x520A, 0x52AA,0x524A,0x520A,0x4852,
  134.     0x6C36,0x2004,0x3FFC,0x0000 };
  135.  
  136. /*
  137.  *    Custom mouse routine
  138.  *    by Ken Hollis
  139.  *
  140.  *    Returns: (0) on any type of failure
  141.  *             (-1) on successful custom mouse transaction
  142.  *             (any other number) to report the mouse result or a
  143.  *                                successful AES mouse transaction
  144.  */
  145. GLOBAL int WGrafMouse(int mo_sfield, ...)
  146. {
  147.     va_list    argptr;
  148.     int    mform, store;
  149.  
  150.     switch(mo_sfield) {
  151.         case GET_MOUSE:
  152.             va_start(argptr, mo_sfield);
  153.             mform = va_arg(argptr, int);
  154.             store = va_arg(argptr, int);
  155.             va_end(argptr);
  156.  
  157.             if (mouseform.forms[cur_mouse]!=0) {
  158.                 if (store) cur_mouse_form = (mouseform.forms[cur_mouse] == 0) ? cur_mouse_form : mouseform.forms[cur_mouse];
  159.                 return((mouseform.forms[cur_mouse] == 0) ? 0 : mouseform.forms[cur_mouse]);
  160.             } else
  161.                 return(0);
  162.  
  163.         case SAVE_MOUSE:
  164.             va_start(argptr, mo_sfield);
  165.             mform = va_arg(argptr, int);
  166.             store = va_arg(argptr, int);
  167.             va_end(argptr);
  168.  
  169.             if (cur_mouse==16)
  170.                 return(0);
  171.             else {
  172.                 if (store) cur_mouse_form = mform;
  173.                 mouseform.forms[cur_mouse++] = mform;
  174.             }
  175.  
  176.             return(-1);
  177.  
  178.         case PREV_MOUSE:
  179.             va_start(argptr, mo_sfield);
  180.             mform = va_arg(argptr, int);
  181.             store = va_arg(argptr, int);
  182.             va_end(argptr);
  183.  
  184.             if (cur_mouse==1)
  185.                 return(0);
  186.             else {
  187.                 if (store) cur_mouse_form = (mouseform.forms[(cur_mouse-1)] == 0) ? cur_mouse_form : mouseform.forms[(cur_mouse-1)];
  188.                 return((mouseform.forms[(cur_mouse-1)] == 0) ? 0 : mouseform.forms[(cur_mouse-1)]);
  189.             }
  190.  
  191.         case NEXT_MOUSE:
  192.             va_start(argptr, mo_sfield);
  193.             mform = va_arg(argptr, int);
  194.             store = va_arg(argptr, int);
  195.             va_end(argptr);
  196.  
  197.             if (cur_mouse==16)
  198.                 return(0);
  199.             else {
  200.                 if (store) cur_mouse_form = (mouseform.forms[(cur_mouse+1)] == 0) ? cur_mouse_form : mouseform.forms[(cur_mouse+1)];
  201.                 return((mouseform.forms[(cur_mouse+1)] == 0) ? 0 : mouseform.forms[(cur_mouse+1)]);
  202.             }
  203.  
  204.         case FIRST_MOUSE:
  205.             va_start(argptr, mo_sfield);
  206.             mform = va_arg(argptr, int);
  207.             store = va_arg(argptr, int);
  208.             va_end(argptr);
  209.  
  210.             if (cur_mouse==1) {
  211.                 if (store) cur_mouse_form = (mouseform.forms[cur_mouse] == 0) ? cur_mouse_form : mouseform.forms[cur_mouse];
  212.                 return((mouseform.forms[cur_mouse] == 0) ? 0 : mouseform.forms[cur_mouse]);
  213.             } else {
  214.                 if (store) cur_mouse_form = (mouseform.forms[1] == 0) ? cur_mouse_form : mouseform.forms[1];
  215.                 return((mouseform.forms[1] == 0) ? 0 : mouseform.forms[1]);
  216.             }
  217.  
  218.         case LAST_MOUSE:
  219.             {
  220.                 int pos = 1;
  221.  
  222.                 va_start(argptr, mo_sfield);
  223.                 mform = va_arg(argptr, int);
  224.                 store = va_arg(argptr, int);
  225.                 va_end(argptr);
  226.  
  227.                 do {
  228.                     if(mouseform.forms[pos]!=0) pos++;
  229.                     else {
  230.                         if (store) cur_mouse_form = mouseform.forms[pos];
  231.                         return(mouseform.forms[pos]);
  232.                     }
  233.                 } while(pos<16);
  234.  
  235.                 return(0);
  236.             }
  237.  
  238.         case CLEAR_MOUSE:
  239.             {
  240.                 int pos = 1;
  241.  
  242.                 do {
  243.                     mouseform.forms[pos++] = 0;
  244.                 } while(pos<16);
  245.  
  246.                 return(-1);
  247.             }
  248.  
  249.         case FIND_MOUSE:
  250.             {
  251.                 int pos = 1;
  252.  
  253.                 va_start(argptr, mo_sfield);
  254.                 mform = va_arg(argptr, int);
  255.                 store = va_arg(argptr, int);
  256.                 va_end(argptr);
  257.  
  258.                 do {
  259.                     if(mouseform.forms[pos]==mform) {
  260.                         if (store) cur_mouse_form = mouseform.forms[pos];
  261.                         return(pos);
  262.                     } else pos++;
  263.                 } while(pos<16);
  264.  
  265.                 return(0);
  266.             }
  267.  
  268.         case NEWPOS_MOUSE:
  269.             va_start(argptr, mo_sfield);
  270.             mform = va_arg(argptr, int);
  271.             va_end(argptr);
  272.  
  273.             cur_mouse = mform;
  274.  
  275.             return(-1);
  276.  
  277.         case ARROW:
  278.         case TEXT_CRSR:
  279.         case BUSYBEE:
  280.         case POINT_HAND:
  281.         case FLAT_HAND:
  282.         case THIN_CROSS:
  283.         case THICK_CROSS:
  284.         case OUTLN_CROSS:
  285.         case M_OFF:
  286.         case M_ON:
  287.             if (cur_mouse_form != mo_sfield) {
  288.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  289.                 return(graf_mouse(mo_sfield, 0L));
  290.             }
  291.             break;
  292.  
  293.         case M_SAVE:
  294.         case M_RESTORE:
  295.         case M_PREVIOUS:
  296.             return(graf_mouse(mo_sfield, 0L));
  297.  
  298.         case INIT_MOUSE:
  299.             if (cur_mouse_form != mo_sfield) {
  300.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  301.                 return(graf_mouse(USER_DEF, (MFORM *) init_mouse));
  302.             }
  303.             break;
  304.  
  305.         case LOAD_MOUSE:
  306.             if (cur_mouse_form != mo_sfield) {
  307.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  308.                 return(graf_mouse(USER_DEF, (MFORM *) loadresource_mouse));
  309.             }
  310.             break;
  311.  
  312.         case LRSLIDE_MOUSE:
  313.             if (cur_mouse_form != mo_sfield) {
  314.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  315.                 return(graf_mouse(USER_DEF, (MFORM *) lrmove_mouse));
  316.             }
  317.             break;
  318.  
  319.         case UDSLIDE_MOUSE:
  320.             if (cur_mouse_form != mo_sfield) {
  321.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  322.                 return(graf_mouse(USER_DEF, (MFORM *) udmove_mouse));
  323.             }
  324.             break;
  325.  
  326.         case URMOVE_MOUSE:
  327.             if (cur_mouse_form != mo_sfield) {
  328.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  329.                 return(graf_mouse(USER_DEF, (MFORM *) ursize_mouse));
  330.             }
  331.             break;
  332.  
  333.         case ULMOVE_MOUSE:
  334.             if (cur_mouse_form != mo_sfield) {
  335.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  336.                 return(graf_mouse(USER_DEF, (MFORM *) ulsize_mouse));
  337.             }
  338.             break;
  339.  
  340.         case LLMOVE_MOUSE:
  341.             if (cur_mouse_form != mo_sfield) {
  342.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  343.                 return(graf_mouse(USER_DEF, (MFORM *) llsize_mouse));
  344.             }
  345.             break;
  346.  
  347.         case LRMOVE_MOUSE:
  348.             if (cur_mouse_form != mo_sfield) {
  349.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  350.                 return(graf_mouse(USER_DEF, (MFORM *) lrsize_mouse));
  351.             }
  352.             break;
  353.  
  354.         case CLIP_MOUSE:
  355.             if (cur_mouse_form != mo_sfield) {
  356.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  357.                 return(graf_mouse(USER_DEF, (MFORM *) clip_mouse));
  358.             }
  359.             break;
  360.  
  361.         case DIALOG_MOUSE:
  362.             if (cur_mouse_form != mo_sfield) {
  363.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  364.                 return(graf_mouse(USER_DEF, (MFORM *) dial_mouse));
  365.             }
  366.             break;
  367.  
  368.         case TEXT_MOUSE:
  369.             if (cur_mouse_form != mo_sfield) {
  370.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  371.                 return(graf_mouse(USER_DEF, (MFORM *) text_mouse));
  372.             }
  373.             break;
  374.  
  375.         case TIMER_MOUSE:
  376.             if (cur_mouse_form != mo_sfield) {
  377.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  378.                 return(graf_mouse(USER_DEF, (MFORM *) timer_mouse));
  379.             }
  380.             break;
  381.  
  382.         case TRASH_MOUSE:
  383.             if (cur_mouse_form != mo_sfield) {
  384.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  385.                 return(graf_mouse(USER_DEF, (MFORM *) trash_mouse));
  386.             }
  387.             break;
  388.  
  389.         default:
  390.             if (cur_mouse_form != mo_sfield) {
  391.                 mouseform.forms[cur_mouse] = cur_mouse_form = mo_sfield;
  392.                 return(graf_mouse(mo_sfield, 0L));
  393.             }
  394.             break;
  395.     }
  396.     return(-1);
  397. }